package com.zwr.sheller.shop.service.impl;

import com.zwr.sheller.core.pojo.Code;
import com.zwr.sheller.shop.mapper.CodeMapper;
import com.zwr.sheller.shop.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 *
 *@author Kang
 *@date
 */
@Service("codeService")
public class CodeServiceImpl implements CodeService {

   @Autowired(required = false)
    CodeMapper codeMapper;

    /**
     * 商户id
     */
    private  Long marketersId = 1L;

    @Override
    public Integer add(Code code) {
       code.setMarketersId(marketersId);
        int insert = codeMapper.insert(code);

        return insert;
    }

    @Override
    public Integer update(Code code) {
        int i = codeMapper.updateByPrimaryKeySelective(code);
        return i;
    }

    @Override
    public List<Map<String, Object>> selectCodeByNameByTimeByManner(Integer manner, Integer timePeriod, String name, Integer page) {
        List<Map<String, Object>> mapList = codeMapper.selectCodeByNameByTimeByManner(manner, timePeriod, name, marketersId, (page - 1) * 3);
        Map map = codeMapper.selectCodeByNameByTimeByMannerCount(manner, timePeriod, name, marketersId);
        return mapList;
    }

    @Override
    public Map selectCodeByNameByTimeByMannerCount(Integer manner, Integer timePeriod, String name) {
        Map map = codeMapper.selectCodeByNameByTimeByMannerCount(manner, timePeriod, name, marketersId);
        return map;
    }

    @Override
    public Integer delete(Long id) {
        Code code=new Code();
        code.setId(id);
        int delete = codeMapper.delete(code);
        return delete;
    }
}
